package com.hotel.comm.lucene.function;

import com.hotel.comm.lucene.condition.ICondition;
import org.apache.commons.collections.CollectionUtils;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;

import java.util.List;

/**
 * @author XuSemon
 * @since 2015-5-4
 */
public class AndSearchCondition implements ICondition {
    /**
     * 查询条件
     */
    private List<ICondition> conditions;

    /**
     * 构造函数
     *
     * @param conditions
     */
    public AndSearchCondition(List<ICondition> conditions) {
        this.conditions = conditions;
    }

    @Override
    public Query getQuery() {
        BooleanQuery query = new BooleanQuery();
        if (CollectionUtils.isNotEmpty(conditions)) {
            for (ICondition condition : conditions) {
                query.add(condition.getQuery(), BooleanClause.Occur.MUST);
            }
        }
        return query;
    }

    public List<ICondition> getConditions() {
        return conditions;
    }

    public void setConditions(List<ICondition> conditions) {
        this.conditions = conditions;
    }
}
